<?php
// 应用公共文件

use think\facade\Log;

if (!function_exists('http_post')) {
    /**
     * POST请求
     */
    function http_post($url, $params, $contentType = false,$auth='')
    {
        $res = $url . '?';
        $p = '';

        foreach ($params as $key => $value) {
            $val = $value;

            if (is_array($value)) {
                $val = json_encode($value);
            }

            $p .= $key . '=' . $val . '&';
        }

        $url_string = substr($res . $p, 0, -1);
        Log::write('adjust-url:'.$url_string);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$auth]);  //fff75341669ce80c26d554697f7c57f3
        $output = curl_exec($ch);
        $error  = curl_error($ch);
        $errno  = curl_errno($ch);

        curl_close($ch);
        return $output;
    }
}
